package ru.bytedog.oiot.counter.bot.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class ConfigService {

    private final Set<String> adminUsers;

    public ConfigService(@Value("${telegram.service.users}") String adminUsersList) {
        this.adminUsers = Optional.ofNullable(adminUsersList)
                .map(users -> users.split(";"))
                .map(Stream::of)
                .map(s -> s.collect(Collectors.toSet()))
                .orElse(Collections.emptySet());
    }

    public boolean isAccessEnabled(String username) {
        return adminUsers.contains(username);
    }

    public int getOtpLength() {
        return 4;
    }

    public int getActualOtpMinutes() {
        return 10;
    }
}
